﻿<template>
  <a-card :bordered="false">
    

    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="10">
          <a-col :md="4" :sm="24">
            <a-form-item label="查询类别">
              <a-select allowClear v-model="queryParam.Condition">
                <a-select-option key="cCusName">客户名称</a-select-option>
                <a-select-option key="cCusCode">客户编码</a-select-option>
                <a-select-option key="code">出库单号</a-select-option>
                <!-- <a-select-option key="cRdCode">收发类别编码</a-select-option>
                <a-select-option key="cPersonCode">业务员编码</a-select-option>
                <a-select-option key="cPTCode">采购类型编码</a-select-option>
                <a-select-option key="cSTCode">销售类型编码</a-select-option> -->
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="24">
            <a-form-item>
              <a-input v-model="queryParam.Keyword" placeholder="关键字" @keydown.enter="getDataList" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-button type="primary" @click="() => {
              this.pagination.current = 1
              this.getDataList()
            }">查询</a-button>
            <a-button style="margin-left: 8px" @click="repossess">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <a-table ref="table" :scroll="{ y: 530 }" :columns="columns" :rowKey="(row, index) => row.ID" :dataSource="data"
      :pagination="pagination" :loading="loading" @change="handleTableChange" :bordered="true" size="small">
      <span slot="CreateTime" slot-scope="CreateTime">{{ timeFormat(CreateTime) }}</span>
      <span slot="state" slot-scope="text, record">
          <template>
            <a-tag v-if="!record.Whethertodestroy" color="orange">
              {{record.state}}
           </a-tag>
           <a-tag v-else color="red">
                {{ record.state }}
             </a-tag>
          </template>
      </span>
      <span slot="action" slot-scope="text, record">
        <template>
          <a @click="handleEdit(record.id)">查看</a>
        </template>
      </span>
    </a-table>

    <edit-form ref="editForm" :parentObj="this"></edit-form>
  </a-card>
</template>

<script>
import EditForm from './EditForm'
import moment from 'moment'
const columns = [
  { title: '出库单号', dataIndex: 'code' },
  { title: '客户编码', dataIndex: 'cCusCode' },
  { title: '客户名称', dataIndex: 'cCusName', width: '20%' },
  {
    title: '单据日期',
    dataIndex: 'madedate',
    customRender: value => {
      if (value) {
        return value.substring(0, 10)
      }
    }
  },

  { title: '单据类型', dataIndex: 'vouchertypeName' },
  { title: '业务类型', dataIndex: 'BusName' },
  // { title: '零售来源类型', dataIndex: 'cSource' },
  // { title: '对应业务单号', dataIndex: 'cBusCode' },
  // { title: '仓库编码', dataIndex: 'cWhCode' },
  // { title: '单据日期', dataIndex: 'dDate' },
  // { title: '收发单据号', dataIndex: 'cCode' },
  // { title: '收发类别编码', dataIndex: 'cRdCode' },
  { title: '制单人', dataIndex: 'maker' },
  // { title: '采购类型编码', dataIndex: 'cPTCode' },
  // { title: '销售类型编码', dataIndex: 'cSTCode' },
  { title: '销售类型', dataIndex: 'StyleNmame' },
  { title: '状态', dataIndex: 'state', scopedSlots: { customRender: 'state' }, },
  // { title: '收货地址', dataIndex: 'cShipAddress', width: '20%', ellipsis: true },
  { title: '操作', dataIndex: 'action', align: 'left', scopedSlots: { customRender: 'action' }, width: '100px',fixed:'right' }
]

export default {
  components: {
    EditForm
  },
  mounted() {
    this.getDataList()
  },
  data() {
    return {
      data: [],
      pagination: {
        current: 1,
        pageSize: 25,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        pageSizeOptions: ['25', '50', '100'], // 设置pageSize的可选值，页面可以通过下拉框进行选择
        showSizeChanger: true
      },
      filters: {},
      sorter: { field: 'dDate', order: 'desc' },
      loading: false,
      columns,
      queryParam: { Condition: 'cCusName' },
      selectedRowKeys: []
    }
  },
  methods: {
    repossess() {
      this.queryParam = { Condition: 'cCusName' }
      this.getDataList();
    },
    handleTableChange(pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }

      this.getDataList()
    },
    getDataList() {
      this.selectedRowKeys = []

      this.loading = true
      // this.data = [
      //   {
      //     cCusCode:'201-00231',
      //     cCusName:'青州亿诚塑业有限公司',
      //     dDate:'2023-10-11',
      //     cVouchName:'销售出库单',
      //     cBusType:'普通销售',
      //     cBusCode:'201-CK23100045',
      //     cCode:'201-SA23100047',
      //     cMaker:'柯宁',
      //     cSTName:'',
      //     cShipAddress:'山东省-潍坊市-青州市-高柳镇西',
      //   }
      // ]
      this.$http
        .post('/InvoiceManagement/ST_RDRecord_b/GetByPageRDRecordList', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: 'id',
          SortType: 'desc',
          // DeptId: this.DeptId,
          Search: [this.queryParam],
          // ...this.filters
        })
        .then(resJson => {
          this.loading = false
          this.data = resJson.Data
          if (this.data) {
            this.data.forEach(item=>{
              item.state = item.Whethertodestroy ?'作废':'正常'
            })
            const pagination = { ...this.pagination }
            pagination.total = resJson.Total
            this.pagination = pagination
          }
        })
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected() {
      return this.selectedRowKeys.length > 0
    },
    handleAdd() {
      this.$refs.editForm.openForm(null, '新建销售出库单主表信息')
    },
    handleEdit(id) {
      this.$refs.editForm.openForm(id, '出库单详情')
    },
    handleDelete(ids) {
      var thisObj = this
      // this.$confirm({
      //   title: '确认删除吗?',
      //   onOk() {
      //     return new Promise((resolve, reject) => {
      //       thisObj.$http.post('/OrderManagement/rdrecord32/DeleteData', ids).then(resJson => {
      //         resolve()

      //         if (resJson.Success) {
      //           thisObj.$message.success('操作成功!')

      //           thisObj.getDataList()
      //         } else {
      //           thisObj.$message.error(resJson.Msg)
      //         }
      //       })
      //     })
      //   }
      // })

      this.$confirm('确认作废吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // thisObj.$http
        //   .post('/OrderManagement/rdrecord32/DeleteData', ids)
        //   .then(resJson => {
        //     // resolve()

        //     if (resJson.Success) {
        //       thisObj.$message.success('操作成功!')

        //       thisObj.getDataList()
        //     } else {
        //       thisObj.$message.error(resJson.Msg)
        //     }
        //   })
      })
    },
    timeFormat(val) {
      // 时间格式化函数
      return moment(val).format('YYYY-MM-DD HH:mm')
    }
  }
}
</script>